package org.apache.ibatis;

import com.sun.management.OperatingSystemMXBean;

import java.io.File;
import java.lang.management.ManagementFactory;

/**
 * 修改运行的 vm options -Xms32m -Xmx32m 快速达到测试结果
 * @author rain.wen
 * @date 2017/12/13.
 */
public class SysTools {
    public static void getSysDiskInfo() {
        File[] disks = File.listRoots();
        for (File file : disks) {
            System.out.print(file.getPath() + "    ");
            System.out.print("空闲未使用 = " + file.getFreeSpace() / 1024 / 1024 + "M" + "    ");
            System.out.print("已经使用 = " + file.getUsableSpace() / 1024 / 1024 + "M" + "    ");
            System.out.print("总容量 = " + file.getTotalSpace() / 1024 / 1024 + "M" + "    ");
            System.out.println();
        }
    }

    public static void getSysMemInfo() {
        OperatingSystemMXBean mem = (OperatingSystemMXBean) ManagementFactory.getOperatingSystemMXBean();
        System.out.println("Total RAM：" + mem.getTotalPhysicalMemorySize() / 1024 / 1024 + "MB");
        System.out.println("Available　RAM：" + mem.getFreePhysicalMemorySize() / 1024 / 1024 + "MB");
    }

    public static void getRuntimeMemInfo() {
        Runtime run = Runtime.getRuntime();
        // 获取开始时内存使用量
        long startMem = run.totalMemory() - run.freeMemory();
        System.out.println("memory> max:" + run.maxMemory() / 1024 / 1024 + " total:" + run.totalMemory() / 1024 / 1024 + " free:" + run.freeMemory() / 1024 / 1024 + " used:" + startMem / 1024 / 1024);
    }
}
